
import java.awt.Color;
import java.awt.Paint;

import net.sf.jasperreports.engine.JRAbstractChartCustomizer;
import net.sf.jasperreports.engine.JRChart;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;

public class BarChartDemo7 extends JRAbstractChartCustomizer {

    static class CustomRenderer extends BarRenderer {

        private final Paint[] colors1;
        private final Paint[] colors2;

        public CustomRenderer(Paint[] colors1, Paint[] colors2) {
            this.colors1 = colors1;
            this.colors2 = colors2;
        }

        //Set custom colors for series according to category    
        @Override
        public Paint getItemPaint(int row, int column) {
            CategoryDataset l_jfcDataset = getPlot().getDataset();
            String l_rowKey = (String)l_jfcDataset.getRowKey(row);
            String l_colKey = (String)l_jfcDataset.getColumnKey(column);

            if ("Insufficient Data".equalsIgnoreCase(l_colKey)) {
                return this.colors2[row % this.colors1.length];
            } else {
                return this.colors1[row % this.colors1.length];
            }
        }
    }

    public void customize(JFreeChart chart, JRChart jasperChart) {

        // Get plot data.
        CategoryPlot categoryPlot = chart.getCategoryPlot();

        // Define colors to be used by series.
        Color[] color1 = new Color[]{new Color(122,0,0), new Color(255,153,0), new Color(211,190,91), new Color(153,204,102), new Color(0,170,0)};
        Color[] color2 = new Color[]{new Color(100,100,100)};

        // Call CustomRenderer using defined color sets.
        categoryPlot.setRenderer(new CustomRenderer(color1,color2));
    }
}